import { ApiProperty } from "@nestjs/swagger";
import { Article } from "@prisma/client";
import { Transform } from "class-transformer";
import { IsInt, IsNotEmpty, IsOptional, IsString, Min } from "class-validator";

import { DbCommonField } from "@/core/types/db-common-field.type";

export class CreateArticleDto implements CustomOmit<Article, "id" | "views" | DbCommonField> {
    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "标题", example: "文章标题", required: true })
    title: string;

    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "内容", example: "文章内容", required: true })
    content: string;

    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "摘要", example: "文章摘要", required: true })
    excerpt: string;

    @IsOptional()
    @Transform(({ value }) => value.trim())
    @IsString()
    @ApiProperty({ description: "封面图片", example: "https://example.com/cover.jpg", required: false })
    coverImage: string;

    @Transform(({ value }) => value.trim())
    @IsString()
    @IsNotEmpty()
    @ApiProperty({ description: "作者", example: "文章作者", required: true })
    author: string;

    @Transform(({ value }) => Number(value))
    @IsInt()
    @Min(0)
    @ApiProperty({ description: "分类ID", example: 0, required: true })
    categoryId: number;
}
